package controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Thanhvienmodel;

import dao.Thanhviendao;

public class Dangnhapcontroller extends HttpServlet{
	

	protected void doGet(HttpServletRequest req,HttpServletResponse rep){
		try {
			String TenDangNhap=req.getParameter("TenDN");
			String MatKhau=req.getParameter("MatKhau");
			String Pagenext="";
			Thanhvienmodel model=Thanhviendao.getThanhVien(TenDangNhap, MatKhau);
			if(model!=null){
				Pagenext="thanhcong.jsp";
				//req.setAttribute("TenCanGan", TenDangNhap);
				//req.setAttribute("Vaitro", model.getVAITRO());
				req.getSession().setAttribute("TenCanGan", TenDangNhap);
				req.getSession().setAttribute("Vaitro", model.getVAITRO());
			}
			else{	
				Pagenext="index.jsp";
				req.setAttribute("ThatBai", "1");
			}
			
			
			RequestDispatcher rd=req.getRequestDispatcher(Pagenext);
			rd.forward(req, rep);
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	

}
